home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 9 / 009.d81 / dos #22 < prev    next >
Encoding:
Text File  |  1985-01-01  |  3.4 KB  |  213 lines

  1.  
  2.       DOS and DONT'S  -- Part 22
  3.       ==========================
  4.  
  5.            by Jimmy Weiler
  6.  
  7.  
  8.  
  9.  
  10.   Now, let's look at the actual BASIC
  11.  
  12. code that might be used to write the
  13.  
  14. name and number into any record.
  15.  
  16.  
  17. 100 PRINT#3,NAME$
  18. 120 PRINT#3,NUMBER$
  19.  
  20.  
  21. (There's more to it than that, but
  22.  we're not ready for the full
  23.  technique just yet.)
  24.  
  25.  
  26. Line 100 prints "SCHLABOTNIK" followed
  27.  
  28. by a carriage return.  Line 120 prints
  29.  
  30. "8687247" followed by a carriage
  31.  
  32. return.  Both fields AND both carriage
  33.  
  34. returns will be written into the file,
  35.  
  36. so when we determine our record size,
  37.  
  38. it will have to be the sum of the
  39.  
  40. maximum lengths of the each of the
  41.  
  42. fields plus the number of fields.
  43.  
  44.   In our case, the desired record
  45.  
  46. length would be 11 + 7 + 2 = 20.
  47.  
  48. (That's eleven characters in the NAME
  49.  
  50. field, seven characters in the NUMBER
  51.  
  52. field, and a total of two fields.)
  53.  
  54. Any record length greater than 20
  55.  
  56. would also work, but would waste space
  57.  
  58. on the disk.  Let's stick with our
  59.  
  60. record length of 89 -- we may decide
  61.  
  62. later that we want to store more
  63.  
  64. information than just names and phone
  65.  
  66. numbers... or someone called Vladimir
  67.  
  68. Byrzschynscvylmynschmylnovsky may
  69.  
  70. join the class.
  71.  
  72.  
  73.         --------------------
  74.  
  75.  
  76.   That's how you open a REL file THE
  77.  
  78. FIRST TIME.  When you open a RELative
  79.  
  80. file that already exists, you don't
  81.  
  82. need to use the LENGTH parameter --
  83.  
  84. the syntax is the same as for a SEQ
  85.  
  86. file.  If you want, you CAN specify
  87.  
  88. the record length, but if you use the
  89.  
  90. wrong length you will get an error 50,
  91.  
  92. RECORD NOT PRESENT.
  93.  
  94.  
  95.         --------------------
  96.  
  97.  
  98.   When you OPEN a disk file, the
  99.  
  100. parameters must all be contained in a
  101.  
  102. single string.  In RELative files,
  103.  
  104. those are the NAME and LENGTH
  105.  
  106. parameters.  In other types, they are
  107.  
  108. the NAME, TYPE, and MODE parameters.
  109.  
  110. (Type is SEQ, PRG, or USR.  Mode is
  111.  
  112. READ or WRITE.)  To make a single
  113.  
  114. string, the individual parameters are
  115.  
  116. CONCATENATED with the BASIC symbol
  117.  
  118. "+".  If your file name, "PHONEFILE"
  119.  
  120. was stored in the variable FILE$, and
  121.  
  122. your record length was stored in the
  123.  
  124. variable L$, you could open a file
  125.  
  126. like this:
  127.  
  128.  
  129. 10 FILE$ = "PHONEFILE"
  130. 20 L$ = CHR$(89)
  131. 30 OPEN 3,8,4,FILE$+",L,"+L$
  132.  
  133.  
  134. Or you could do the concatenation
  135.  
  136. first:
  137.  
  138.  
  139. 10 F$ = "PHONEFILE,L,"+CHR$(89)
  140. 30 OPEN 3,8,4,F$
  141.  
  142.  
  143. Or you could put EVERYTHING between
  144.  
  145. the quotes.  Did you know that
  146.  
  147. CHR$(89) is the letter "Y"?
  148.  
  149.  
  150. 30 OPEN 3,8,4,"PHONEFILE,L,Y"
  151.  
  152.  
  153. Of course, this third technique is
  154.  
  155. enormously confusing when you look at
  156.  
  157. your code later and try to figure out
  158.  
  159. what record length "Y" will produce.
  160.  
  161. I don't recommend it.
  162.  
  163.          -----------------
  164.  
  165.   Let's look at that "bug" I mentioned
  166.  
  167. earlier -- record lengths of 58 are
  168.  
  169. not allowed.  Well, as you may know,
  170.  
  171. CHR$(58) is the colon.  You have
  172.  
  173. probably also seen statements like
  174.  
  175. this:  OPEN 15,8,15,"S0:SCRATCHFILE".
  176.  
  177. This is the DOS command to SCRATCH
  178.  
  179. (remove) the file named "SCRATCHFILE"
  180.  
  181. from disk drive 0.  Most of us don't
  182.  
  183. have a drive 1, but the 0 is still
  184.  
  185. required for many commands.  The point
  186.  
  187. is that the COLON is the special
  188.  
  189. character used to separate a DOS
  190.  
  191. command from the filename upon which
  192.  
  193. it is supposed to act.
  194.  
  195.   Another syntax for opening our REL
  196.  
  197. file with a record length of 89 is:
  198.  
  199. OPEN 3,8,4,"0:PHONEFILE,L,Y".  If the
  200.  
  201. record length was 58, the parameters
  202.  
  203. would be "0:PHONEFILE,L,:".  The
  204.  
  205. second colon is obviously in the wrong
  206.  
  207. place, and DOS knows it, thus the
  208.  
  209. SYNTAX ERROR.
  210.  
  211.  
  212. -------- Continued in Part 23 --------
  213.